package com.china08.yxyapi.api.manage.edu.platform.continuedu.lesson;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.continuedu.YxyContinueduLessonItem;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.continuedu.YxyContinueduLessonItemRepository;

import io.swagger.annotations.ApiOperation;

@CrossOrigin
@RestController
public class YxyContinueduLessonListItemController extends YxyApiBaseController {

    @Autowired
    YxyContinueduLessonItemRepository itemRepository;

    @ApiOperation(value = "")
    @RequestMapping(value = "/api_yw/manage/edu/platform/continuedu/lesson/item/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<RespModel> precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        String lessonId = reqModel.lessonId;
        List<YxyContinueduLessonItem> list = itemRepository.findByLessonId(lessonId);
        List<RespModel> returnList = new ArrayList<RespModel>();
        for (YxyContinueduLessonItem item : list) {
            RespModel respModel = new RespModel();
            respModel.itemId = item.getId();
            respModel.itemName = item.getTitle();
            returnList.add(respModel);
        }
        return returnList;
    }

    public static class ReqModel extends YxyApiReqModel {
        public String lessonId;

        @Override
        public void autoCheck() {
        }
    }

    public static class RespModel extends YxyApiRespModel {
        public String itemName;
        public String itemId;
    }
}
